package com.suxii.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.suxii.mapper.ChatUserMapper;
import com.suxii.pojo.ChatUser;
import com.suxii.service.UserService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<ChatUserMapper, ChatUser> implements UserService {
    @Override
    public ChatUser user(ChatUser chatUser) {
        ChatUser user = lambdaQuery()
                .select(ChatUser::getName,ChatUser::getUid)
                .eq(ChatUser::getUid, chatUser.getUid())
                .eq(ChatUser::getPassword, chatUser.getPassword())
                .one();
        return user;
    }

    @Override
    public List<ChatUser> get(List<Integer> uids) {
        List<ChatUser> chatUsers=new ArrayList<>();
        uids.forEach(uid-> {
            ChatUser user = lambdaQuery()
                    .select(ChatUser::getName, ChatUser::getUid)
                    .eq(ChatUser::getUid, uid)
                    .one();
            chatUsers.add(user);
        });
        return chatUsers;
    }


    @Override
    public ChatUser findFriend(ChatUser chatUser) {
        return lambdaQuery()
                .select(ChatUser::getName, ChatUser::getUid)
                .eq(ChatUser::getUid, chatUser.getUid())
                .one();
    }
}
